/* for XMLPlatformUtils::Initialize() and Terminate() */
#include <xercesc/util/PlatformUtils.hpp>

/* for dom common */
#include <xercesc/dom/DOM.hpp>

/* for */
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMDocument.hpp>
#include <xercesc/dom/deprecated/DOMParser.hpp>
/* for parser */
#include <xercesc/parsers/XercesDOMParser.hpp>

/* for XMLException */
#include <xercesc/util/OutOfMemoryException.hpp>

#include <iostream>

#include "handle_opts.h"
#include "argument.h"
using namespace std;
XERCES_CPP_NAMESPACE_USE;


int main( int argc , char ** argv ){
	int i;
	handle_opts( argc , argv , opts , opts_count );
	for( i=0 ; i<opts_count ; i++){
		print_args(opts[i]);
	}
	char *input_file = opts[INPUT_FILE].ret_value.content.content_string;

	/* Initialize the environment */
	try{
		XMLPlatformUtils::Initialize();
	}catch( const XMLException & exception ){

		cerr	<< "Error during Xerces-c Initialization.\n"
			<<" Exception message:"
			<< XMLString::transcode(exception.getMessage()) 
			<< endl;

		return exception.getCode();
	}

	/* Create a parser */
//	XercesDOMParser *parser = new XercesDOMParser;
//
//	parser->setValidationScheme(XercesDOMParser::Val_Auto);
//	parser->setDoNamespaces(true);
//	parser->setDoSchema(true);
////	parser->setValidationSchemaFullChecking(true);
////	parser->setCreateEntityReferenceNodes(true);
//	/* Ignore the whitespace */
//	parser->setIncludeIgnorableWhitespace(false);	
//	
///********** Do something at here ***********/	
//	try{
//		parser->parse( input_file );
//	}catch( const OutOfMemoryException& ){
//		cerr<<"parser failed !!!!"<<endl;
//		return -1;
//	}catch( const XMLException & exception ){
//		cerr<<"XMLException"<<endl;
//		return -2;
//	}catch( const DOMException & exception ){
//		cerr<<"DOMException"<<endl;
//		return -3;
//	}catch( ... ){
//		cerr<<"Unknown Exception"<<endl;
//		return -4;
//	}
//
//	try{
//		XMLCh tempStr[100];
//		XMLString::transcode("LS" , tempStr , 99);
//		DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
//
//		DOMDocument *doc = parser->getDocument();
//		DOMElement * element = doc->getDocumentElement();
//		DOMNodeList * child = element->getChildNodes();
//		cout<<"list number:"<< child->getLength()<<endl;
//
//		DOMNodeIterator * iter;
//		iter = doc->createNodeIterator( doc , DOMNodeFilter::SHOW_ALL|DOMNodeFilter::SHOW_ATTRIBUTE , NULL , true );
//
//		DOMNode * current_p;
//
//		for( current_p = iter->nextNode() ; current_p != 0 ; current_p = iter->nextNode() ){
//			cout << XMLString::transcode(current_p->getNodeName()) << endl;
//			if(current_p->getNodeValue())
//				cout << "<content:\t" <<XMLString::transcode(current_p->getNodeValue())<<"endl>"<<endl;
///*			if(DOMNode::TEXT_NODE == current_p->getNodeType()){
//				cout << "\t" <<XMLString::transcode(current_p->getNodeValue())<<endl;
//			}
//
//			if( current_p->hasAttributes()){
//				DOMNamedNodeMap * mynodemap = current_p->getAttributes();
//				XMLSize_t attrib_count = mynodemap->getLength();
//				XMLSize_t i;
//
//				for( i=0 ; i < attrib_count ; i++ ){
//					DOMNode * node_p = mynodemap->item(i);
//
//					cout 	<< "\t\t" 
//						<< XMLString::transcode( node_p->getNodeName() )
//						<< "="
//						<< XMLString::transcode( node_p->getNodeValue() )
//						<< endl;
//				}
//			}else{
//				cout << "\tno attributes" << endl;
//			}
//*/
//		}
//	}catch(...){
//	}
//	cout << "*****" <<endl;
XercesDOMParser * parser = new XercesDOMParser;
parser->setIncludeIgnorableWhitespace(false);
parser->setDoNamespaces(true);
parser->setDoSchema(true);   
parser->setValidationScheme(XercesDOMParser::Val_Auto);
	
parser->parse( "test.xml" );
DOMDocument  *doc = parser->getDocument();
DOMElement	*root = doc->getDocumentElement();
DOMNodeList	*list = root->getChildNodes();
int len = list->getLength();
printf("\n list size = %d", len);

/********** /Do somethine at here **********/

	/* Clean up the environment */
	XMLPlatformUtils::Terminate();
	return 0;
}

